<?php
namespace app\admin\controller;

use app\admin\model\Admin as AdminModel;
use think\Validate;

class Admin extends Base
{

    public function admin_list()
    {
        $admin_list = AdminModel::order('id ASC')->paginate();

        return view('admin_list', compact('admin_list'));
    }

    public function admin_modify()
    {
        $user = $this->user;

    	return view('admin_modify', compact('user'));
    }

    public function admin_modify_post()
    {
        $param = $this->request->param();
        // dump($param);exit;
        $validate = new Validate([
            ['name', 'require', '请输入真实姓名'],
            ['mobile', 'require', '请输入联系手机'],
            ['email', 'require', '请输入电子邮箱']
        ]);
        if(!$validate->check($param)) {
            return error($validate->getError());
        }
        $update['name'] = $param['name'];
        $update['mobile'] = $param['mobile'];
        $update['email'] = $param['email'];
        $where['id'] = $this->user->id;

        if($param['password']){
            $update['mobpasswordle'] = md5($param['mobile']);
        }

        $falg = AdminModel::where($where)->update($update);
        if ($falg || $falg == false) {
            return success($falg, '更新成功');
        }
        return error('更新失败');
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        $delete = AdminModel::destroy($id);
        if ($delete) {
            return success($delete, '删除成功');
        }
        return error('删除失败');
    }
}
